<?php
//验证是不是微信5.0 版本
function validateWeiXin()
{
    $weiXinStatus  =  false;
    if (strpos($_SERVER['HTTP_USER_AGENT'], "MicroMessenger") !== false ) {
        $weiXinStatus = true;
    }
    return $weiXinStatus;
}

//验证是否是支付宝
function validateAliapp()
{
    return strpos($_SERVER['HTTP_USER_AGENT'], "Alipay");
}

//过滤微信表情
function filterEmoji($str)
{
    $str = preg_replace_callback(
        '/./u',
        function ($match) {
            return strlen($match[0]) >= 4 ? '' : $match[0];
        },
        $str
    );
    return $str;
}

/**
 * 删除过期文件
 * @param  [type]  $filePath   文件路径
 * @param  array  $format     文件格式
 * @param  integer $expiration 过期日期
 * @return [type]              [description]
 */
function deleteExpiredFiles($filePath, $format = '.png', $expiration = 7200)
{
    $filePath = realpath($filePath);
    $current_dir = @opendir($filePath);
    $now = time();
    $len = strlen($format);
    while ($filename = @readdir($current_dir)) {
        if (substr($filename, -$len) === $format && is_file($filePath. DIRECTORY_SEPARATOR .$filename)) {
            if ((filectime($filePath. DIRECTORY_SEPARATOR .$filename) + $expiration) < $now) {
                @unlink($filePath. DIRECTORY_SEPARATOR. $filename);
            }
        }
    }
    @closedir($current_dir);
}
